﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using PMS.XCMG.Util;

namespace Giant.Entity
{
    /// <summary>
    /// 扩展表
    /// </summary>
    public class ExpandEntity<K> : BaseEntity<K>
    {
        public string ExpStr1 { get; set; }
        public string ExpStr2 { get; set; }
        public string ExpStr3 { get; set; }
        public string ExpStr4 { get; set; }
        public string ExpStr5 { get; set; }
        public string ExpStr6 { get; set; }
        public string ExpEnum1 { get; set; }
        public string ExpEnum2 { get; set; }
        public string ExpEnum3 { get; set; }
        public string ExpEnum4 { get; set; }
        public string ExpEnum5 { get; set; }
        public string ExpEnum6 { get; set; }
        public int? ExpInt1 { get; set; }
        public int? ExpInt2 { get; set; }
        public int? ExpInt3 { get; set; }
        public int? ExpInt4 { get; set; }
        public int? ExpInt5 { get; set; }
        public int? ExpInt6 { get; set; }
        public decimal? ExpNum1 { get; set; }
        public decimal? ExpNum2 { get; set; }
        public decimal? ExpNum3 { get; set; }
        public decimal? ExpNum4 { get; set; }
        public decimal? ExpNum5 { get; set; }
        public decimal? ExpNum6 { get; set; }
        public DateTime? ExpDate1 { get; set; }
        public DateTime? ExpDate2 { get; set; }
        public DateTime? ExpDate3 { get; set; }
        public DateTime? ExpDate4 { get; set; }
        public DateTime? ExpDate5 { get; set; }
        public DateTime? ExpDate6 { get; set; }
        public string ExpSelect1 { get; set; }
        public string ExpSelect2 { get; set; }
        public string ExpSelect3 { get; set; }
        public string ExpSelect4 { get; set; }
        public string ExpSelect5 { get; set; }
        public string ExpSelect6 { get; set; }
    }
    public class ExpandEntity : ExpandEntity<string>
    { }


    /// <summary>
    /// 默认实体配置
    /// OnModelCreating
    /// </summary>
    /// <typeparam name="T"></typeparam>
    /// <typeparam name="K"></typeparam>
    public class ExpandEntityTypeConfig<T, K> : BaseEntityTypeConfig<T, K>, IEntityTypeConfiguration<T>
        where T : ExpandEntity<K>
    {
        public override void Configure(EntityTypeBuilder<T> builder)
        {
            base.Configure(builder);

            #region 主外键关系

            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.ExpStr1).HasMaxLength(EntityDefinition.DefLargeColLen);
            builder.Property(p => p.ExpStr2).HasMaxLength(EntityDefinition.DefLargeColLen);
            builder.Property(p => p.ExpStr3).HasMaxLength(EntityDefinition.DefLargeColLen);
            builder.Property(p => p.ExpStr4).HasMaxLength(EntityDefinition.DefLargeColLen);
            builder.Property(p => p.ExpStr5).HasMaxLength(EntityDefinition.DefLargeColLen);
            builder.Property(p => p.ExpStr6).HasMaxLength(EntityDefinition.DefLargeColLen);
            builder.Property(p => p.ExpEnum1).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpEnum2).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpEnum3).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpEnum4).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpEnum5).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpEnum6).HasMaxLength(EntityDefinition.DefSmallColLen);

            builder.Property(p => p.ExpNum1).HasColumnType("decimal(18,2)");
            builder.Property(p => p.ExpNum2).HasColumnType("decimal(18,2)");
            builder.Property(p => p.ExpNum3).HasColumnType("decimal(18,2)");
            builder.Property(p => p.ExpNum4).HasColumnType("decimal(18,2)");
            builder.Property(p => p.ExpNum5).HasColumnType("decimal(18,2)");
            builder.Property(p => p.ExpNum6).HasColumnType("decimal(18,2)");

            builder.Property(p => p.ExpSelect1).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpSelect2).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpSelect3).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpSelect4).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpSelect5).HasMaxLength(EntityDefinition.DefSmallColLen);
            builder.Property(p => p.ExpSelect6).HasMaxLength(EntityDefinition.DefSmallColLen);
            #endregion

            #region 备注
            #endregion
        }
    }

    public class ExpandEntityTypeConfig<T> : ExpandEntityTypeConfig<T, string>, IEntityTypeConfiguration<T>
        where T : ExpandEntity
    {
        public override void Configure(EntityTypeBuilder<T> builder)
        {
            base.Configure(builder);

            #region 主外键关系

            #endregion

            #region 字段属性:最大长度,是否必需,默认值
            builder.Property(p => p.Id).HasMaxLength(EntityDefinition.DefSmallColLen);
            #endregion

            #region 备注

            #endregion
        }
    }
}
